package com.easy.order.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.easy.common.bean.Orders;
import com.easy.common.service.IOrderService;
import com.easy.common.util.ResultData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("order")
public class OrderController {
    @Autowired
    IOrderService orderService;

    public ResultData insert(@RequestBody Orders product) {
        Orders data=orderService.insert(product);
        System.out.println(data);
        return ResultData.success(data);
    }
    @PutMapping("/")
    public ResultData update(@RequestBody Orders product) {
        Orders data=orderService.update(product);
        return ResultData.success(data);
    }
    @DeleteMapping("/{id}")
    @GetMapping("/{id}")
    public ResultData getByID(@PathVariable Integer id) {
        Orders product=orderService.getByID(id);
        return ResultData.success(product);
    }
    @GetMapping("/userpage")
    public ResultData getListByPage(IPage page, Integer userid) {
        IPage<Orders> data=orderService.getListByUserID(page,userid);
        return ResultData.success(data);
    }
    @GetMapping("/customerpage")
    public ResultData getListByCustomerID(IPage page, Integer customerid) {
        IPage<Orders> data=orderService.getListByUserID(page,customerid);
        return ResultData.success(data);
    }

}
